<?php

class crossSelling {


  function getRelatedSubjectsCatToArt (&$shop,$params){
    $this->rs      = $shop->call('dbaCrossSelling','getArticlesCatFieldsSF',$shop->getHttpVar('aid'),array('display_url As tpl','art_id As id','name','short_descr','amount As price'));
    $this->artcount = 0;
    $this->catcount = 0;
    $this->repcount = 0;
    if ($this->rs['articles'] && $this->rs['reports']) return true;
  }

  function getRelatedSubjects (&$shop,$params){
    $this->rs      = $shop->call('dbaCrossSelling','getallFieldsSF',$shop->getHttpVar('aid'),array('display_url As tpl','cross_id As id','name','short_descr','amount As price'));
    $this->artcount = 0;
    $this->catcount = 0;
    $this->repcount = 0;
    if ($this->rs['articles'] && $this->rs['categories'] && $this->rs['reports']) return true;
  }

  function nextRelatedArticle (&$shop,$params = '') {
     if ($this->artcount < count($this->rs['articles'])){
        while (list($name,$value) = each($this->rs['articles'][$this->artcount])){
	  if (!preg_match('/^\d+$/',$name)){
	   $shop->setBlockVar($name,$value);
	  }
	}
	$this->artcount++;
        //var_dump($this->rs['articles'][$this->artcount]);
	return true;
      } else {
        unset($this->rs['articles']);
	return;
      }
  }

  function nextRelatedCategory (&$shop,$params = '') {
     if ($this->catcount < count($this->rs['categories'])){
        while (list($name,$value) = each($this->rs['categories'][$this->catcount])){
	  if (!preg_match('/^\d+$/',$name)){
	   $shop->setBlockVar($name,$value);
	  }
	}
	$this->catcount++;
	return true;
      } else {
        unset($this->rs['categories']);
	return;
      }
  }

  function nextRelatedReport (&$shop,$params = '') {
     if ($this->repcount < count($this->rs['reports'])){
        while (list($name,$value) = each($this->rs['reports'][$this->repcount])){
	  if (!preg_match('/^\d+$/',$name)){
	   $shop->setBlockVar($name,$value);
	  }
	}
	$this->repcount++;
	return true;
      } else {
        unset($this->rs['reports']);
	return;
      }
  }

  function relatedCategoryLink (&$shop,$params) {
    $link = '<a href="'.$shop->getVar('SCRIPT_NAME').'?a=cc&dc=<%=$id%>&t='.$shop->cfgTplFrame['artlist'].'&tr=<%=$TEMPLATE_ROOT%>" target="'.$shop->cfgTplFrame['artlist'].'">'.$params[0].'</a>';
    $link =  $shop->mod['parser']->evalVars($link);
    $shop->out($link);
  }

  function relatedCategories () {
    if ($this->rs['categories']) return true;
  }

  function relatedArticles () {
    if ($this->rs['articles']) return true;
  }

  function relatedReports () {
    if ($this->rs['reports']) return true;
  }

}

?>